/*
 * DateUtil.java
 *
 * Created on September 27, 2002, 4:35 PM
 */

package com.mymaxis.utils;


import java.util.*;
import java.text.*;

import com.mymaxis.ebppx.EbppxConstants;

/**
 *
 * @author  Lendy
 * @version
 */
public class DateUtil {

    /** Creates new DateUtil */
    public DateUtil() {
    }

    //
    public static String formatDate(Date dt) {
        SimpleDateFormat formatter = new SimpleDateFormat(EbppxConstants.DATE_FORMAT+" "+EbppxConstants.TIME_FORMAT);
        return formatter.format(dt);
    }

    public static String formatDate(Date dt, String format) {
        SimpleDateFormat formatter = new SimpleDateFormat(format);
        return formatter.format(dt);
    }

    /**
     * Creates a <code>Date</code> object from a string representation of a date (with the pattern "dd-MM-yyyy").
     *
     * @param   dateStr     The date string
     * @return          A <code>Date</code> object that represents the date implied in the string
     * @throws  ParseException  If the date string is not valid
     */
  public static Date createDateLocalDash(String dateStr) throws ParseException {
    SimpleDateFormat formatter;
    if (dateStr.length() < 10){
	    formatter = new SimpleDateFormat("dd-MM-yy");
    } else{
        formatter = new SimpleDateFormat("dd-MM-yyyy");
    }
    formatter.setLenient(false);
    return formatter.parse(dateStr);
  }

    /**
     * Creates a <code>Date</code> object from a string representation of a date (with the pattern "yyyyMMdd").
     *
     * @param   dateStr     The date string
     * @return          A <code>Date</code> object that represents the date implied in the string
     * @throws  ParseException  If the date string is not valid
     */
  public static Date createDateUniversal(String dateStr) throws ParseException {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
    formatter.setLenient(false);
    return formatter.parse(dateStr);
  }


}
